package com.deer.wms.system.manage.web;

import com.deer.wms.system.manage.model.organization.UserOrganization;
import com.deer.wms.system.manage.model.organization.UserOrganizationCriteria;
import com.deer.wms.system.manage.model.organization.UserOrganizationDto;
import com.deer.wms.system.manage.service.UserOrganizationService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;

import java.util.List;

/**
* Created by guo on 2019/11/05.
*/
@Api(description = "用户货主关联信息api接口")
@RestController
@RequestMapping("/user/organizations")
public class UserOrganizationController {

    @Autowired
    private UserOrganizationService userOrganizationService;

    @PostMapping("/insert")
    public Result add(@RequestBody UserOrganization userOrganization) {
        userOrganizationService.save(userOrganization);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/delete")
    public Result delete(@PathVariable Integer id) {
        userOrganizationService.removeById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody UserOrganization userOrganization) {
        userOrganizationService.updateById(userOrganization);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/{id}")
    public Result detail(@PathVariable Integer id) {
        UserOrganization userOrganization = userOrganizationService.getById(id);
        return ResultGenerator.genSuccessResult(userOrganization);
    }

    @GetMapping("/list")
    public Result list(UserOrganizationCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<UserOrganizationDto> list = userOrganizationService.findList(criteria);
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

}
